package com.control;

import com.dao.StudentDao;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author :wn
 * @program : 项目五登录界面
 * @descript : 更新控制器
 * @create :2020-11-08 14:47
 */
@WebServlet(value = "/updateStudentInformation")
public class UpdateControl  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name=new String (req.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
        String age=new String (req.getParameter("age").getBytes("ISO-8859-1"),"UTF-8");
        String sex=new String (req.getParameter("sex").getBytes("ISO-8859-1"),"UTF-8");
        String sdept=new String (req.getParameter("sdept").getBytes("ISO-8859-1"),"UTF-8");
        try {
            boolean updateWether=new StudentDao().updateWay(name,age,sex,sdept);
            if(updateWether){
                String updateInformation="修改成功！！";
                req.setAttribute("updateInformation",updateInformation);
                req.getRequestDispatcher("/updateInterface.jsp").forward(req,resp);
            }else{
                String updateInformation="修改失败！！";
                req.setAttribute("updateInformation",updateInformation);
                req.getRequestDispatcher("/updateInterface.jsp").forward(req,resp);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}
